ATTACHMENT_fun_Plugins.push(function(img){
    if(img.attach_type=='.jpg' || img.attach_type=='.png' || img.attach_type=='.gif'){
        return "<a href='#' onclick=\"attachment_photo_coll_add("+img.attach_id+",'"+img.attach_thumb+"','',0);return false\">图集</a>";
    }else{
        return false;
    }
}
)
//{"photo_id":"1","photo_coll_id":"6","attach_id":"200","photo_sort":"0","photo_desc":""}
attachment_photo_coll_add_all=function(all){
    if(typeof(all) =='object'){
        for(var i=0;i<all.length;i++){
            var o = all[i];
            attachment_photo_coll_add(o.attach_id,ROOT+o.attach_thumb,o.photo_desc,o.photo_sort);
        }
    }
}

attachment_photo_coll_add=function(attach_id,attach_thumb,$textarea,$sort){
    var inputs=$('photo_coll_hidden_inputs').$$('input');
    for(var i = 0 ; i<inputs.length;i++){
        if(inputs[i].value==attach_id){
            return;
        }
    }
    
    var inputEle=document.createElement('input');
    inputEle.type='hidden';
    inputEle.value=attach_id;
    inputEle.name='Component[photos][attach_id][]';
    $('photo_coll_hidden_inputs').appendChild(inputEle);

    var one=document.createElement('div');
    one.className='photo_coll_one_div';
    one.id='photo_coll_one_div_'+attach_id;
    one.innerHTML=
    "<div class='photo_coll_one_div_left'><img src='"+attach_thumb+"' onload='attachment_photo_align(this)'/></div>"+
    "<div class='photo_coll_one_div_right'>描述:<br/><textarea name='Component[photos][attach_desc]["+attach_id+"]'>"+$textarea+"</textarea><br/>"+
    "排序:<input name='Component[photos][attach_sort]["+attach_id+"]' class='input_text_photo_coll_2' value='"+$sort+"' /><br/>"+
    "<input type='button' value='丢掉图片' onclick='photo_coll_one_delete("+attach_id+")' /></div>";
    $('photo_coll_big_div').appendChild(one);
}

photo_coll_one_delete=function(id){
    try{
        $('photo_coll_big_div').removeChild($('photo_coll_one_div_'+id));
        var inputs=$('photo_coll_hidden_inputs').$$('input');
        for(var i = 0 ; i<inputs.length;i++){
            if(inputs[i].value==id){
                $('photo_coll_hidden_inputs').removeChild(inputs[i]);
                continue;
            }
        }
    }catch(e){}
}

attachment_photo_align=function(img){
    var xyz=_zoom(img.width,img.height,140,140);
    img.width=xyz[0];
    img.height=xyz[1];
    img.style.border="1px solid teal";
    img.style.marginTop=parseInt((150-img.height)/2) + 'px';
}